package com.example.bjsfpost.domain;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;

import java.io.Serializable;

@Data
public class ParamPostResponseDO implements Serializable {

    private static final long serialVersionUID = 1L;

    /* {
        "success": true,
            "code": "00000",
            "data": {
        "RETURN_MSG": "",
                "RETURN_SUBRC": 0
    }
    {
        "success": true,
            "code": "00000",
            "data": {
        "RETURN_MSG": "类型test7 未配置,请检查配置文件",
                "RETURN_SUBRC": 1
    }
    */
    private Boolean success;
    private String code;
    private ReturnData data;

    public static ParamPostResponseDO httpError(){
        ParamPostResponseDO result = new ParamPostResponseDO();
        result.setData(ReturnData.fail("http send error"));
        result.setCode("-1");
        result.setSuccess(false);
        return result;
    }

/*    public static ParamPostResponseDO custom(Object data){
        ParamPostResponseDO result = new ParamPostResponseDO();
        result.setData(data);
        result.setCode("500");
        result.setSuccess(false);
        return result;
    }*/

    public static ParamPostResponseDO ok(){
        ParamPostResponseDO result = new ParamPostResponseDO();
        result.setCode("200");
        result.setSuccess(true);
        result.setData(ReturnData.ok("ok"));
        return result;
    }
    public static ParamPostResponseDO ok(Object data){
        ParamPostResponseDO result = new ParamPostResponseDO();
        result.setCode("200");
        result.setSuccess(true);
        result.setData(ReturnData.ok(data.toString()));
        return result;
    }
    @Data
    public static class ReturnData implements Serializable{
        /*"RETURN_MSG": "物料号4000032292,版本C.3,类型4-装置 在视图wcadmin.view_4_Device 查询不到数据",
        "RETURN_SUBRC": 1*/
        @JSONField(name = "RETURN_MSG")
        private String RETURN_MSG;
        //0成功 1失败
        @JSONField(name = "RETURN_SUBRC")
        private Integer RETURN_SUBRC;

        public static ReturnData fail(String msg){
            ReturnData returnData = new ReturnData();
            returnData.setRETURN_MSG(msg);
            returnData.setRETURN_SUBRC(1);
            return returnData;
        }
        public static ReturnData ok(String msg){
            ReturnData returnData = new ReturnData();
            returnData.setRETURN_MSG(msg);
            returnData.setRETURN_SUBRC(0);
            return returnData;
        }
    }
}